package ks.client.controllers;

import ks.client.UserContext;
import ks.client.ipc.Client;
import ks.client.lobby.Lobby;
import ks.framework.interfaces.IProcessMessage;

/**
 * Deal with requests to disconnect.
 * 
 * This is an internal controller used by the KS framework code and that is why
 * it doesn't implement {@link IProcessMessage}. You will not need to modify this
 * class.
 * 
 * @author George Heineman 
 */
public class DisconnectController {
	/** Lobby to be managed. */
	Lobby lobby;
	
	/** 
	 * Connection controller needs to know the Lobby to manage its functionality.
	 * 
	 * @param room
	 */
	public DisconnectController (Lobby lobby) {
		this.lobby = lobby;
	}

	public boolean process(UserContext context) {
		Client client = context.getClient();
		client.disconnect();
		
		// if we get here, we may yet be trying to connect... 
		lobby.append("disconnecting from: " + context.getHost() + ":" + context.getPassword());
		return true;
	}

}
